#include <iostream>
#include <cctype>
#include <string>
#include <limits>
#include "Character.h"
#include "Shop.h"

using namespace std;

//---------------------------------------------------------------------------

void attributes(Character&, int&);

int main()
{
	string answer;
	int points = 24;
	string charname;

	
	try
	{
		Shop shop("weapons.txt", "armor.txt");
		Character Build;
		Build.setStr(8);
		Build.setCon(8);
		Build.setDex(8);
		Build.setWis(8);
		Build.setCha(8);


		cout<<"Your character currently looks like the following: "<<endl;

		Build.display();

		cout<<endl;

		do
		{
			cout<<"Would you like to modify your character? (Y or N)  -> ";
			cin >> answer;
		
		


			if (toupper(answer[0]) == 'Y')
			{	
				system ("cls");
				attributes (Build, points);
			}
			

		}while(toupper(answer[0]) == 'Y');
		
		cout<<"Please enter the name that you have chosen for your character. -> ";

		cin.clear(); 
	
		getline(cin, charname);

		cout << endl;
		
		Build.setName(charname);
		
		
		cout<<"Great you have now finished building and naming your character."<<endl;

		Build.setGold(100 + (10 * Build.getChaMod()) + (10 * Build.getWisMod()));
		

		Build.display();

		cout<<endl;

		cout<<"You can now begin playing the game."<<endl<<endl;

		shop.enter(Build);

		return 0;
	}
	catch (int)
	{
		cout << "Missing file for armor, terminating early" << endl;
		return 1;
	}
	catch (float)
	{
		cout << "Missing file for weapons, terminating early" << endl;
		return 1;
	}

	
}


////////////////////////////////////End of Main////////////////////////////////////////////



void attributes(Character& Build, int& points)
{
	int option;
	
	
	do
	{
		/*********************Builds cells to load attributes into*********************/
		
		int str;
		int dex;
		int con;
		int wis;
		int cha;
		
		int add_or_delete = 0;
		
		/*******************************************************************************/

		/**************Loads cells by calling functions from character class************/
		
		str = Build.getStr();
		dex = Build.getDex();
		con = Build.getCon();
		wis = Build.getWis();
		cha = Build.getCha();


		/***********************************Menu****************************************/
		
		Build.display();
		cout << endl;

		cout<<"You have a total of "<<points<<" points to spend on the attribute that you choose."<<endl<<endl;
		cout<<"1."<<'\t'<<"Add Strength"<<endl;
		cout<<"2."<<'\t'<<"Subract Strength"<<endl;
		cout<<"3."<<'\t'<<"Add Dexterity"<<endl;
		cout<<"4."<<'\t'<<"Subtract Dexterity"<<endl;
		cout<<"5."<<'\t'<<"Add Constitution"<<endl;
		cout<<"6."<<'\t'<<"Subtract Constitution"<<endl;
		cout<<"7."<<'\t'<<"Add Wisdom"<<endl;
		cout<<"8."<<'\t'<<"Subtract Wisdom"<<endl;
		cout<<"9."<<'\t'<<"Add Charisma"<<endl;
		cout<<"10."<<'\t'<<"Subtract Charisma"<<endl;
		cout<<"11."<<'\t'<<"View Character"<<endl;
		cout<<"12."<<'\t'<<"Done modifying attributes"<<endl;
		cout<<"Please choose one of the above options. -> ";
		cin>>option;

		system("cls");

		/*******************************End Menu***************************************/



		if (option > 12)
		{
			cout<<"Invalid reponse. Please re-enter your option.\n";

			cout<<"You have a total of "<<points<<" points to spend on the attribute that you choose."<<endl<<endl;
			cout<<"1."<<'\t'<<"Add Strength"<<endl;
			cout<<"2."<<'\t'<<"Subract Strength"<<endl;
			cout<<"3."<<'\t'<<"Add Dexterity"<<endl;
			cout<<"4."<<'\t'<<"Subtract Dexterity"<<endl;
			cout<<"5."<<'\t'<<"Add Constitution"<<endl;
			cout<<"6."<<'\t'<<"Subtract Constitution"<<endl;
			cout<<"7."<<'\t'<<"Add Wisdom"<<endl;
			cout<<"8."<<'\t'<<"Subtract Wisdom"<<endl;
			cout<<"9."<<'\t'<<"Add Charisma"<<endl;
			cout<<"10."<<'\t'<<"Subtract Charisma"<<endl;
			cout<<"11."<<'\t'<<"View Character"<<endl;
			cout<<"12."<<'\t'<<"Done modifying attributes"<<endl;
			cout<<"Please choose one of the above options. -> ";
			cout << "-> ";
			cin>>option;
		}


		switch (option)
		{
		case 1: 
				cout << "Current points in " << "Strength: " << str << endl; 
				cout<<"Please enter the amount of points that you would like to add"<<endl;
				cout<<"	to strength. -> ";
				cin>>add_or_delete;
				if (add_or_delete > points)
				{
					cout<<"You do not have that many points to spend on this attribute."<<endl;
					cout<<"You only have "<<points<<" points that you can spend."<<endl;
					cout<<"No points were added from this attribute, returning to main menu."<<endl;
					system("PAUSE");
				}
				else
				{
					points = points - add_or_delete;
					str = str + add_or_delete;
					Build.setStr(str);
				}

				break;

		case 2:	
				cout << "Current points in " << "Strength: " << str << endl; 
				cout<<"Please enter the amount of points that you would like to remove"<<endl;
				cout<<"	from strength. -> ";
				cin>>add_or_delete;
				
				if (add_or_delete >= str)
				{
					cout<<"You do not have that many points for this attribute."<<endl;
					cout<<"You only have "<<str<<" points for strength."<<endl;
					cout<<"No points were removed from this attribute, returning to main menu."<<endl;
					system("PAUSE");
					
				}
				else
				{
					points = points + add_or_delete;
					str = str - add_or_delete;
					Build.setStr(str);
				}

				break;

		case 3:	
				cout << "Current points in " << "Dexterity: " << dex << endl; 
				cout<<"Please enter the amount of points that you would like to add"<<endl;
				cout<<"	to Dexterity. -> ";
				cin>>add_or_delete;
				if (add_or_delete > points)
				{
					cout<<"You do not have that many points to spend on this attribute."<<endl;
					cout<<"You only have "<<points<<" points that you can spend."<<endl;
					cout<<"No points were added from this attribute, returning to main menu."<<endl;
					system("PAUSE");
				}
				else
				{
					points = points - add_or_delete;
					dex = dex + add_or_delete;
					Build.setDex(dex);
				}

				break;

		case 4: 
				cout << "Current points in " << "Dexterity: " << dex << endl;
				cout<<"Please enter the amount of points that you would like to remove"<<endl;
				cout<<"	from dexterity. -> ";
				cin>>add_or_delete;
				
				if (add_or_delete >= dex)
				{
					cout<<"You do not have that many points for this attribute."<<endl;
					cout<<"You only have "<<dex<<" points for strength."<<endl;
					cout<<"No points were removed from this attribute, returning to main menu."<<endl;
					system("PAUSE");
				}
				else
				{
					points = points + add_or_delete;
					dex = dex - add_or_delete;
					Build.setDex(dex);
				}

				break;

		case 5:	
				cout << "Current points in " << "Constitution: " << con << endl;
				cout<<"Please enter the amount of points that you would like to add"<<endl;
				cout<<"	to constitution. -> ";
				cin>>add_or_delete;
				if (add_or_delete > points)
				{
					cout<<"You do not have that many points to spend on this attribute."<<endl;
					cout<<"You only have "<<points<<" points that you can spend."<<endl;
					cout<<"No points were added from this attribute, returning to main menu."<<endl;
					system("PAUSE");
				}
				else
				{
					points = points - add_or_delete;
					con = con + add_or_delete;
					Build.setCon(con);
				}

				break;

		case 6:	
				cout << "Current points in " << "Constitution: " << con << endl;
				cout<<"Please enter the amount of points that you would like to remove"<<endl;
				cout<<"	from constitution. -> ";
				cin>>add_or_delete;
				
				if (add_or_delete >= con)
				{
					cout<<"You do not have that many points for this attribute."<<endl;
					cout<<"You only have "<<con<<" points for strength."<<endl;
					cout<<"No points were removed from this attribute, returning to main menu."<<endl;
					system("PAUSE");
					
				}
				else
				{
					points = points + add_or_delete;
					con = con - add_or_delete;
					Build.setCon(con);
				}

				break;

		case 7:	
				cout << "Current points in " << "Wisdom: " << wis << endl;
				cout<<"Please enter the amount of points that you would like to add"<<endl;
				cout<<"	to wisdom. -> ";
				cin>>add_or_delete;
				if (add_or_delete > points)
				{
					cout<<"You do not have that many points to spend on this attribute."<<endl;
					cout<<"You only have "<<points<<" points that you can spend."<<endl;
					cout<<"No points were added from this attribute, returning to main menu."<<endl;
					system("PAUSE");
				}
				else
				{
					points = points - add_or_delete;
					wis = wis + add_or_delete;
					Build.setWis(wis);
				}

				break;

		case 8: 
				cout << "Current points in " << "Wisdom: " << wis << endl;
				cout<<"Please enter the amount of points that you would like to remove"<<endl;
				cout<<"	from wisdom. -> ";
				cin>>add_or_delete;
				
				if (add_or_delete >= wis)
				{
					cout<<"You do not have that many points for this attribute."<<endl;
					cout<<"You only have "<<wis<<" points for strength."<<endl;
					cout<<"No points were removed from this attribute, returning to main menu."<<endl;
					system("PAUSE");
					
				}
				else
				{
					points = points + add_or_delete;
					wis = wis - add_or_delete;
					Build.setWis(wis);
				}

				break;


		case 9: 
				cout << "Current points in " << "Charisma: " << cha << endl;
				cout<<"Please enter the amount of points that you would like to add"<<endl;
				cout<<"	to charisma. -> ";
				cin>>add_or_delete;
				if (add_or_delete > points)
				{
					cout<<"You do not have that many points to spend on this attribute."<<endl;
					cout<<"You only have "<<points<<" points that you can spend."<<endl;
					cout<<"No points were added from this attribute, returning to main menu."<<endl;
					system("PAUSE");
				}
				else
				{
					points = points - add_or_delete;
					cha = cha + add_or_delete;
					Build.setCha(cha);
				}

				break;


		case 10: 
				cout << "Current points in " << "Charisma: " << cha << endl;
				cout<<"Please enter the amount of points that you would like to remove"<<endl;
				cout<<"	from charisma. -> ";
				cin>>add_or_delete;
				
				if (add_or_delete >= cha)
				{
					cout<<"You do not have that many points for this attribute."<<endl;
					cout<<"You only have "<<cha<<" points for strength."<<endl;
					cout<<"No points were removed from this attribute, returning to main menu."<<endl;
					system("PAUSE");
					
				}
				else
				{
					points = points + add_or_delete;
					cha = cha - add_or_delete;
					Build.setCha(cha);
				}

				break;


		case 11: cout<<"Your character currently looks like the following: "<<endl;

				Build.display();

				cout<<endl;
				system("PAUSE");

				break;

		case 12: break;
			

		}




		system ("cls");


	}while (option < 12);
	
}
